/**
 * money utils (与钱相关的工具)
 */
const _ = require('lodash');

let moneyUtils = module.exports = {};

moneyUtils.getMoney = function (money) {
    if (_.isNumber(money)) {
        return money * 10000;
    }

    if (_.isString(money)) {
        money = money.replace(/[^\d.]/g, '');
        return parseFloat(money * 10000);
    }

    return undefined;
};

moneyUtils.string2Float = function (string) {
    if (!string) {
        return null;
    }
    let result = string.replace(/[^\d.]/g, '');

    if (result.length === 0) {
        result = 0;
    }

    result = parseFloat(result);

    return result;
};


